package com.dzu.easy;

/**
 * @author ZhaoDong
 * @date 2022/11/14 15:37
 * @description 461. 汉明距离
 */
public class Test461 {

    public static void main(String[] args) {


        System.out.println(hammingDistance(1, 4));

        System.out.println(Integer.bitCount(1 ^ 4));
    }
    public  static int hammingDistance(int x, int y) {
        int count = 0;
        while (x != 0 || y != 0) {
            if ((x & 1) != (y & 1)) {
                count++;
            }

            x >>= 1;
            y >>= 1;

        }
        return count;
    }

    public int hammingDistance2(int x, int y) {
        int s = x ^ y, ret = 0;
        while (s != 0) {
            ret += s & 1;
            s >>= 1;
        }
        return ret;
    }

}
